@extends('admin.layout.index')
@section('content') 
    <div class="portlet box green">

        <div class="portlet-title">

            <div class="caption"><i class="icon-globe"></i><font><font>友情链接管理</font></font></div>

                <div class="tools">

                    <a href="javascript:;" class="reload"></a>

                    <a href="javascript:;" class="remove"></a>

                </div>

            </div>

            <div class="portlet-body">

                <div id="sample_1_wrapper" class="dataTables_wrapper form-inline" role="grid">
                     <div class="row-fluid">
                         <div class="span6">
                            <div id="sample_1_length" class="dataTables_length"></div>
                                            
                                
                        </div>
                        <div class="span6">
                             <div class="dataTables_filter" id="sample_1_filter"></div>
                         </div>
                            <table class="table table-striped table-bordered table-hover table-full-width dataTable" id="sample_1" aria-describedby="sample_1_info">

                     <thead>
                         <div class="clearfix">

                             <div class="btn-group">

                                <button id="sample_editable_1_new" class="btn green" onClick="location.href='/admin/link/create'">

                                 添加友情链接 <i class="icon-plus"></i>

                                 </button>


                                 <!-- <button id="sample_editable_1_new" class="btn green" onClick="location.href='/admin/link/edit'">

                                全部友情链接 <i class="icon-all"></i>

                                </button> -->

                            </div>
                        </div>
                            <table>
                             <tr role="row">
                                 <th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending" style="width: 268px;">
                                 <font><font>排序</font></font></th>
                                 <th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" aria-label="" style="width: 31px;"><font><font>Id</font></font></th>
                                 <th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending" style="width: 268px;">
                                 <font><font>链接名称</font></font></th>
                                <th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending" style="width: 268px;">
                                 <font><font>URL</font></font></th>
                                 <th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending" style="width: 268px;">
                                 <font><font>操作</font></font></th>
                                            
                                            
                                            
                                            
                                            
                                  
                             </tr>
                             @foreach($data as $k=>$v) 
                            <tr>

                                <td class="tc">
                                    <input type="text" name="order" value="{{$v['order']}}" onchange="changeOrder(this,{{$v->id}})" style="width:30px;" >
                                </td>

                                 <td class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" aria-label="" style="width: 31px;"><font><font>{{$v['id']}}</font></font></td>

                                <td class="sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending" style="width: 268px;">
                                <font><font>{{$v['title']}}</font></font></td>
                                <td class="hidden-480 sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending" style="width: 246px;">
                                <font><font>{{$v['url']}}</font></font></td>
                                           

                                <td class="hidden-480 sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending" style="width: 246px;">
                                <form method="post" action="/admin/link/{{$v['id']}}">
                                    {{csrf_field()}}
                                    <input type="hidden" value="DELETE" name="_method">
                                    <button type="button" class="btn blue" onclick="dellink({{$v['id']}})"><i class="icon-trash"></i>删除</button>
                                </form>
                                                
                                </td>
                                            
                            </tr>
                            @endforeach
                        </thead>
                    </table>
                    
                    
                    
                    <div class="dataTables_paginate paging_bootstrap pagination" style="float:right;">
                        {!! $data->appends($request)->render()!!}
                    </div>
                    
                    
        <script>
            function dellink(id){

                
            layer.confirm('是否确认删除？', {
                btn: ['确认','取消'] //按钮
            }, function(){
                //            jQuery.post(url,data,success(data, textStatus, jqXHR),dataType)
                $.post('{{url('admin/link/')}}/'+id,{'_token':'{{csrf_token()}}','_method':'delete'},function(data){
                    //console.log(data);
//                    删除成功
                    if(data.status == 0){
                        layer.msg(data.msg, {icon: 6});
                        location.href = location.href;
                    }else{
                        layer.msg(data.msg, {icon: 5});
                        location.href = location.href;
                    }
                });

            }, function(){

            });
        }


             function changeOrder(obj,id){
        
//            获取文本框的值
           var order =  $(obj).val();
//            向服务器发送ajax请求，修改当前记录的order字段的值
            $.post('{{url('admin/link/changeorder')}}',{'_token':'{{csrf_token()}}','id':id,'order':order},function(data){
                // alert(data);
//                    修改成功
                // console.log(msg)
                if(data.status == 0){
                    layer.msg(data.msg, {icon: 6});
                    location.href = location.href;
                }else{
                    layer.msg(data.msg, {icon: 5});
                    location.href = location.href;
                }
            });
        }
        </script>

@endsection